home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.069 < prev    next >
Encoding:
Text File  |  1990-05-29  |  17.4 KB  |  342 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIgs
  8. #69:    The Ins and Outs of Slot Arbitration
  9.  
  10. Revised by:    Matt Deatherage                                       May 1990
  11. Written by:    Matt Deatherage                                 September 1989
  12.  
  13. This Technical Note discusses the concept of a 14-slot Apple IIgs system 
  14. through dynamic software slot arbitration.  It presents concepts of which all 
  15. IIgs programmers should be aware for full compatibility.
  16. Changes since September 1989:  Removed the section which stated that this Note 
  17. showed how to switch slots in a way that does not interfere with slot 
  18. arbitration and replaced it with the proper description, which is how to 
  19. search a 14-slot system for peripherals and their identification bytes.
  20. _____________________________________________________________________________
  21.  
  22.  
  23. History
  24.  
  25. The Apple II has always had seven slots.  In some cases (e.g., IIe), one of 
  26. the slots was handled specially by the hardware, or (e.g., IIc) there was no 
  27. hardware present for peripheral cards at all.  But there have always been 
  28. seven "slots" with firmware at location $Cn00 (where n is the slot number).  
  29. If there was no firmware, there was no peripheral connected.
  30.  
  31. With the introduction of the Apple IIgs, the Apple II family saw its first 14-
  32. slot system.  Seven hardware slots are provided for peripheral cards (like on 
  33. the IIe), and seven internal "ports" with connectors on the back panel are 
  34. provided by the system (like on the IIc).  Since $C800 and above cannot be 
  35. used for additional slots (that space is shared between all interface cards), 
  36. each of the seven internal ports is matched with one of the slots, and either 
  37. the port or the slot is enabled at any given time.  The IIgs hardware allows 
  38. switching between the two, so all fourteen slots could be used more or less 
  39. simultaneously.
  40.  
  41. This situation posed a problem--the Apple II had only a disk operating system, 
  42. not an overall operating system.  Access to non-disk devices (i.e., character 
  43. devices, like a serial card) was not arbitrated by the system in any way.  The 
  44. world was used to seven, and only seven, slots.  Attempting to use more in a 
  45. shared system such as the IIgs resulted in somebody jumping to slot firmware 
  46. that somebody else had switched out.  This tended to crash the system.
  47.  
  48. Then came GS/OS.  With its centralized mechanism for dispatching to all 
  49. devices connected to a system, GS/OS provides hope (for the first time) that a 
  50. central routing mechanism can dynamically arbitrate between slots and ports, 
  51. allowing the use of all 14 at one time.  This is called dynamic slot 
  52. arbitration, and is handled by a portion of GS/OS referred to as the Slot 
  53. Arbiter.
  54.  
  55. Although the Slot Arbiter does not function in System Software 5.0 or earlier, 
  56. it may function in the future.  A skeleton is present in version 5.0 and later 
  57. that accepts Slot Arbiter calls, but the skeleton does not actually switch any 
  58. slots.  This Note details the Slot Arbiter functionality and shows how to 
  59. search a 14-slot system for peripherals and their identification bytes.
  60.  
  61. Note:  The Slot Arbiter must not be used unless GS/OS is the current 
  62.        operating system.
  63.  
  64. The Slot Arbiter
  65.  
  66. The Slot Arbiter is accessed through the GS/OS system service call vector 
  67. DYN_SLOT_ARBITER ($01FCBC).  On ROM 03 and later, the vector is duplicated at 
  68. $E10208.  Entry to the Slot Arbiter is via a JSL instruction, and exit is via 
  69. RTL.  The parameters are as follows:
  70.  
  71. Entry:
  72.     A = Slot to be selected (defined below)
  73.     X = Undefined (or Bit Encoded Slot Configuration)
  74.     Y = Undefined
  75.     B = Undefined
  76.     D = Undefined
  77.     P = N V M X D I Z C  E
  78.         x x 0 0 0 x x x  0
  79.  
  80. Exit:
  81.     A = Error Code
  82.     X = Bit Encoded Slot Configuration
  83.     Y = Undefined
  84.     B = Unchanged
  85.     D = Undefined
  86.     P = N V M X D I Z C  E
  87.         x x 0 0 0 x x 0  0        If A = $0000 (no error)
  88.         x x 0 0 0 x x 1  0        If A = $0010 (slot not available)
  89.  
  90. The slot number in the A register tells the Slot Arbiter what you are 
  91. requesting.  Bits 0-2 are the slot number in the range 0 through 7.  Bit 3 is 
  92. set if you are requesting an external slot and clear if you are requesting an 
  93. internal port.  Taken together, bits 0-3 give slot numbers of $0-$7 for 
  94. internal ports and $9-$F for external slots.  This is the same way that slot 
  95. numbers are returned by the GS/OS DInfo command.
  96.  
  97. Bits 8 and 9 of the slot number indicate the action you wish the Slot Arbiter 
  98. to take.  A value in these two bits of 00 asks the Slot Arbiter to switch in 
  99. the slot identified in bits 0 through 3.  If both bits are set to 11, the Slot 
  100. Arbiter restores all the slots to match the Bit Encoded Slot Configuration 
  101. present in the X register.  Bit Encoded Slot Configurations are discussed in 
  102. the next section of this Note.  Values other than 00 or 11 in bits 8 and 9 are 
  103. reserved and must not be used by applications.
  104.  
  105. Bit 15 of the slot number is set if the slot selection has no slot 
  106. dependencies.  When the Slot Arbiter is asked to switch in a slot with no slot 
  107. dependencies, it does no actual switching, although it returns a Bit Encoded 
  108. Slot Configuration in the X register.  The slot number and the definitions of 
  109. the individual bits are illustrated in Figure 1.
  110.  
  111.      ___________________|___________
  112.     |F|E|D|C|B|A|9|8|7|6|5|4|3|2|1|0|
  113.     |_|_________|___|_______|_|_____|
  114.      |     |      |     |    |   |___ Slot
  115.      |     |      |     |    |_______ 0 = Internal; 1 = External
  116.      |     |      |     |____________ Zero
  117.      |     |      |__________________ Call Type Identifier
  118.      |     |                            00 = Slot Request
  119.      |     |                            11 = Select by Bit Encoded
  120.      |     |                                 Slot Configuration
  121.      |     |_________________________ Zero
  122.      |_______________________________ Slot Dependent or Slot Independent
  123.  
  124.                   Figure 1-Slot Number and Bit Definitions
  125.  
  126. Bit Encoded Slot Configurations
  127.  
  128. Every call to the Slot Arbiter returns (on exit) a miniature picture of the 
  129. slot configuration in the X register (as it was on entry).  This picture has 
  130. one bit set for each of the 14 slots; if the bit is set, then the 
  131. corresponding slot is switched in.  Bits 0 and 8 are reserved and are always 
  132. clear.  This picture is called a Bit Encoded Slot Configuration.
  133.  
  134. Since each external slot has the same number as an internal port (with bit 3 
  135. set), and since such pairs share the same address space, it follows that both 
  136. of them may not be enabled at the same time.  For example, port 5 and slot 5 
  137. ($D) both may not be enabled.  This makes the high byte of the Bit Encoded 
  138. Slot Configuration the eXclusive-OR of the low byte (excluding bits 0 and 8, 
  139. which are always clear).  Figure 2 illustrates the Bit Encoded Slot 
  140. Configuration.
  141.  
  142.              _______________________________
  143.             |F|E|D|C|B|A|9|8|7|6|5|4|3|2|1|0|
  144.              |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_ 0
  145.              | | | | | | | | | | | | | | |___ 1 = slot 1 active
  146.              | | | | | | | | | | | | | |_____ 1 = slot 2 active
  147.              | | | | | | | | | | | | |_______ 1 = slot 3 active
  148.              | | | | | | | | | | | |_________ 1 = slot 4 active
  149.              | | | | | | | | | | |___________ 1 = slot 5 active
  150.              | | | | | | | | | |_____________ 1 = slot 6 active
  151.              | | | | | | | | |_______________ 1 = slot 7 active
  152.              | | | | | | | |_________________ 0
  153.              | | | | | | |___________________ 1 = slot 9 active
  154.              | | | | | |_____________________ 1 = slot 10 active
  155.              | | | | |_______________________ 1 = slot 11 active
  156.              | | | |_________________________ 1 = slot 12 active
  157.              | | |___________________________ 1 = slot 13 active
  158.              | |_____________________________ 1 = slot 14 active
  159.              |_______________________________ 1 = slot 15 active
  160.  
  161.                   Figure 2-Bit Encoded Slot Configuration
  162.  
  163. By fully using the slot number parameter, the Slot Arbiter returns any aspect 
  164. of the current slot configuration.  Following are a few examples:
  165.  
  166.             Slot number    Action Taken by Slot Arbiter
  167.             _________________________________________________________
  168.             $8000          Returns current Bit Encoded Slot 
  169.                            Configuration in the X register.  This 
  170.                            number asks the Slot Arbiter to switch in 
  171.                            with no slot dependencies (no switching), 
  172.                            so it just returns the Bit Encoded Slot 
  173.                            Configuration.
  174.             $0300          Restore from Bit Encoded Slot 
  175.                            Configuration.  This command, when paired 
  176.                            with the one above, can be used to save 
  177.                            and restore a slot environment.
  178.             $0005          Asks the Slot Arbiter for internal port 5.
  179.             _________________________________________________________
  180.  
  181.  
  182. The Impact on Applications and Drivers
  183.  
  184. Applications which correctly do all input and output through GS/OS are 
  185. affected by slot arbitration, except that they find more devices available.  
  186. GS/OS uses the slot number parameter in the Device Information Block to call 
  187. the Slot Arbiter, making sure the slot is available for the device before it 
  188. gets control.  However, there are some applications (such as peripheral card 
  189. configuration programs) which go directly to firmware or hardware, not using 
  190. GS/OS.  Perhaps the card has no ROM, so there is no generated driver, or 
  191. perhaps there is no loaded driver and the generated driver does not control 
  192. certain aspects of the hardware.  In any case, such applications are directly 
  193. impacted by slot arbitration.
  194.  
  195. Slot Searching
  196.  
  197. The first problem is finding the hardware.  In a 14-slot system, it's not 
  198. suitable to just look for ID bytes between $C100 and $C700--two peripherals may 
  199. be sharing each of those pages of slot ROM space.  Drivers must examine all 14 
  200. slots, with the aid of the Slot Arbiter.  The following sample code 
  201. demonstrates this technique:
  202.  
  203. find_slot          lda    #$8000           ; request current Bit Encoded Slot 
  204. Configuration
  205.                    jsl    slot_arbiter
  206.                    phx                     ; save it on the stack
  207.  
  208.                    lda    #$000F           ; start with slot 15
  209.                    sta    slot_number      ; be sure of the data bank when
  210.                                            ; doing this!
  211.  
  212. slot_search        lda    slot_number      ; get the slot number to examine
  213.                    jsl    slot_arbiter     ; and ask for it
  214.                    bcs    continue_search  ; if an error, then don't look here
  215.                    jsr    check_for_hw     ; this routine looks for your 
  216. hardware
  217.                    bcc    found_my_hw      ; if found it, we're done searching
  218. continue_search    dec    slot_number      ; try the next lower slot
  219.                    bpl    slot_search      ; (if there are any left, of course)
  220.  
  221. found_my_hw        plx                     ; get Bit Encoded Slot Configuration
  222.                                            ; from stack
  223.                    lda    #$0300           ; and tell the Slot Arbiter to 
  224.                                            ; restore from it
  225.                    jsl    slot_arbiter
  226.  
  227. ; We're done.  Our slot number is in the location slot_number.
  228.  
  229. Note:  You must restore the previous slot configuration when 
  230.        searching for a slot.  This is vital to device drivers during the 
  231.        Drvr_Startup call, and failure to do so at other times may break 
  232.        older, seven-slot applications.
  233.  
  234. The Slot Arbiter attempts to maintain a static seven-slot system for 
  235. applications as reflected by the user's Control Panel settings.  This system 
  236. allows older applications to continue to work, as something they find in an 
  237. older, seven-slot scan is still present.  Newer applications may wish to 
  238. consider implementing a 14-slot scan, but any slot not present in the static 
  239. seven-slot environment requires a call to the Slot Arbiter before and after 
  240. every access to that device.  The overhead in such instances may be 
  241. intolerable.  Apple recommends that if an application requires hardware that 
  242. cannot be found in a seven-slot scan, it request the user to set the Control 
  243. Panel to make the hardware available and restart the system.
  244.  
  245. Using Slot-Dependent Hardware
  246.  
  247. Applications which have slot dependencies must call the Slot Arbiter before 
  248. each use of the slot in question.  Since Slot Arbitration changes the 
  249. environment to which Apple IIgs programs have become accustomed, everyone has 
  250. a better chance of working by sticking to the general Apple IIgs rule of "put 
  251. back what you use when you're done with it."  Ask for the slot, use it, then 
  252. restore the previous Bit Encoded Slot Configuration.  (If you use multiple 
  253. slots, you might wish to get the Bit Encoded Slot Configuration, save a copy, 
  254. modify it to reflect the slots you want, and restore from the modified 
  255. version.)
  256.  
  257. Note:  Peripherals accessed through GS/OS do not have to call the 
  258.        Slot Arbiter; GS/OS handles this task automatically.
  259.  
  260. There are certain applications with more specialized needs, such as high-
  261. speed, single character input or output.  In such cases, the Slot Arbiter may 
  262. be a bottleneck.  When a slot is not switched, the Slot Arbiter returns 
  263. quickly, but when a slot must be switched, it takes a significant amount of 
  264. time.  Doubling that significant time for switching in and restoring gives a 
  265. substantial overhead for each hardware access, which may be too much for some 
  266. applications.
  267.  
  268. Note:  It is far better to write a GS/OS driver to deal with hardware 
  269.        than to write a slot-dependent application to control it.  A slot-
  270.        dependent application must deal with the Slot Arbiter, and the user must 
  271.        quit the current application to run your application just to change some 
  272.        aspect of the hardware.  Writing a GS/OS driver lets any application, 
  273.        desk accessory, or CDev control your hardware with regular GS/OS calls.
  274.  
  275.  
  276. Problems with Slot-Dependent Tools
  277.  
  278. Code designed before the Slot Arbiter may have slot-dependencies that cause 
  279. unexpected problems when dynamic slot arbitration is fully implemented.  This 
  280. list includes some of the Apple IIgs System Software.  Specifically, the Text 
  281. Tools and the FWEntry call in the Miscellaneous Tools present problems with 
  282. dynamic slot arbitration.
  283.  
  284. Text Tools
  285.  
  286. When using the Text Tools to specify a device for input, output, or error, the 
  287. value specified (a four-byte parameter) is assumed to be a slot number if it 
  288. is in the range 0-7.  The Text Tools were not designed to use Slot Arbiter-
  289. style slot numbers, and this causes a compatibility problem.
  290.  
  291. The Text Tools were modified in System Software 5.0 to recognize Slot Arbiter-
  292. style slot numbers where possible.  The trick is that it's not possible as 
  293. often as we'd like.  External slots are specified by using slot numbers 9 
  294. through 15; if such a slot number is used as input to a Text Tools call, the 
  295. appropriate Slot Arbiter call is made and that external slot is used if it can 
  296. be made available.  However, internal port numbers are in the range 1-7--the 
  297. same range used by the old Text Tools to indicate which of two peripherals was 
  298. switched in for a particular slot.  The Text Tools cannot assume that you are 
  299. requesting an internal slot when using a slot number between one and seven.
  300.  
  301. For example, your old application might do a seven-slot search and find a 
  302. parallel printer card in slot 1 (where the Control Panel setting for that slot 
  303. is "Your Card").  If the Text Tools assumed all slot numbers in the range one 
  304. through seven meant internal ports, your application would actually access the 
  305. internal port 1 firmware every time it tried to access the parallel card it 
  306. found in slot 1; this problem occurs since old applications don't know and 
  307. don't care about internal or external slots.
  308.  
  309. The Text Tools may be used to access any external slot (if available), but 
  310. they may only be used to access internal ports that are set to internal in the 
  311. Control Panel.  The Text Tools slot numbers zero through seven always match 
  312. the Control Panel settings.
  313.  
  314. Apple strongly recommends that the Text Tools not be used.  GS/OS character-
  315. based drivers are preferable for standard character input and output.  The 
  316. Text Tools may be used for specialized purposes; however, you cannot access 
  317. some internal ports and other components of the system that are not well-
  318. behaved.  Doing so could cause your application to trash memory or media.  You 
  319. must assume these risks when using the Text Tools.
  320.  
  321. FWEntry
  322.  
  323. The Miscellaneous Tools call FWEntry should not be used to access entry points 
  324. on a peripheral card (entry points in the $Cxxx range).  As discussed, a 
  325. poorly-behaved routine could switch the slot from one you've identified to 
  326. something else between the time you identify the slot and issue the FWEntry 
  327. call.  Furthermore, the space between $C800 through $CFFF cannot be identified 
  328. as belonging to any given slot, and the Slot Arbiter more or less guarantees 
  329. that it won't be what you expect.  Accesses to peripheral card ROM space 
  330. ($Cxxx) should only be made by GS/OS drivers.  FWEntry must not be used to 
  331. access $Cxxx addresses.
  332.  
  333. FWEntry is still safe to use for addresses in the $D000-$FFFF range.
  334.  
  335.  
  336. Further Reference
  337. _____________________________________________________________________________
  338.   o  Apple IIGS Toolbox Reference, Volume 2
  339.   o  Apple IIGS Firmware Reference
  340.   o  Apple IIGS Hardware Reference
  341.   o  GS/OS Reference
  342.